package com.qdsgjsfk.vision.ui;
//
//import android.graphics.Color;
//import android.support.v7.app.AppCompatActivity;
//import android.os.Bundle;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.text.TextUtils;
//import android.view.KeyEvent;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.LinearLayout;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import com.baidu.location.BDAbstractLocationListener;
//import com.baidu.location.BDLocation;
//import com.baidu.location.LocationClient;
//import com.baidu.location.LocationClientOption;
//import com.rest.business.RestProxy;
//import com.rest.response.AreaResponse;
//import com.rest.response.IaBaseResponse;
//import com.rest.response.SchoolResponse;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import butterknife.BindView;
//import butterknife.OnClick;
//import io.reactivex.Observer;
//import io.reactivex.disposables.Disposable;
//import qdsg.com.R;
//import qdsg.com.base.BaseActivity;
//import qdsg.com.ui.dialog.ClassDialog;
//
//public class MainActivity extends BaseActivity {
//
//    @BindView(R.id.recyclerView_province)
//    RecyclerView recyclerView_province;
//    @BindView(R.id.recyclerView_area)
//    RecyclerView recyclerView_area;
//    @BindView(R.id.recyclerView_city)
//    RecyclerView recyclerView_city;
//    @BindView(R.id.recyclerView_school)
//    RecyclerView recyclerView_school;
//    @BindView(R.id.area_container)
//    LinearLayout area_container;
//    @BindView(R.id.tv_area)
//    TextView tv_area;
//    @BindView(R.id.tv_location)
//    TextView tv_location;
//
//    String currentProvince, currentCity, currentArea, currentSchool, currentClass, currentLocation;
//
//    private MyAdapter myAdapter_province, myAdapter_area, myAdapter_city;
//    private MySchoolAdapter myAdapter_school;
//    private List<AreaResponse.Area> list_province = new ArrayList<>();
//    private List<AreaResponse.Area> list_city = new ArrayList<>();
//    private List<AreaResponse.Area> list_area = new ArrayList<>();
//    private List<SchoolResponse.School> list_school = new ArrayList<>();
//
//    private ClassDialog mClassDialog;
//    private int currentAreaId;
//    private boolean isBack = true;
//
//    public LocationClient mLocationClient = null;
//    private MyLocationListener myListener = new MyLocationListener();
//
//    @Override
//    protected void initViews() {
//        myAdapter_province = new MyAdapter(list_province);
//        myAdapter_area = new MyAdapter(list_area);
//        myAdapter_city = new MyAdapter(list_city);
//        myAdapter_school = new MySchoolAdapter(list_school);
//        recyclerView_province.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView_province.setAdapter(myAdapter_province);
//        recyclerView_city.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView_city.setAdapter(myAdapter_city);
//        recyclerView_area.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView_area.setAdapter(myAdapter_area);
//        recyclerView_school.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView_school.setAdapter(myAdapter_school);
//        btn_back.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (isBack) {
//                    finish();
//                } else {
//                    area_container.setVisibility(View.VISIBLE);
//                    recyclerView_school.setVisibility(View.GONE);
//                    isBack = true;
//                }
//            }
//        });
//
//
//        //BDAbstractLocationListener为7.2版本新增的Abstract类型的监听接口
////原有BDLocationListener接口暂时同步保留。具体介绍请参考后文中的说明
//        mLocationClient = new LocationClient(getApplicationContext());
//        //声明LocationClient类
//        mLocationClient.registerLocationListener(myListener);
//        //注册监听函数
//        LocationClientOption option = new LocationClientOption();
//
//        option.setIsNeedAddress(true);
////可选，是否需要地址信息，默认为不需要，即参数为false
////如果开发者需要获得当前点的地址信息，此处必须为true
//
//        mLocationClient.setLocOption(option);
//        mLocationClient.start();
//    }
//
//    @Override
//    protected void initData() {
//        getAreaByLevel("", 0);
//
//    }
//
//    @Override
//    protected int getLayoutResource() {
//        return R.layout.activity_main;
//    }
//
//
//    class MyAdapter extends RecyclerView.Adapter<MyAdapter.Holder> {
//
//        List<AreaResponse.Area> list;
//        int type;//0  地区  1 学校
//
//        public MyAdapter(List<AreaResponse.Area> list) {
//            this.list = list;
//        }
//
//
//        @Override
//        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//            Holder holder = new Holder(getLayoutInflater().inflate(R.layout.item_area, parent, false));
//            return holder;
//        }
//
//        @Override
//        public void onBindViewHolder(final Holder holder, final int position) {
//            if (list.get(position).flag) {
//                holder.tv_name.setTextColor(Color.parseColor("#005faf"));
//            } else {
//                holder.tv_name.setTextColor(Color.parseColor("#333333"));
//            }
//            holder.tv_name.setText(list.get(position).areaname);
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (list.get(position).level == 1) {
//                        getAreaByLevel(list.get(position).id + "", 1);
//                        tv_area.setText(list.get(position).areaname);
//                        currentProvince = list.get(position).areaname;
//                        for (int i = 0; i < list.size(); i++) {
//                            list.get(i).flag = false;
//                        }
//                        list.get(position).flag = true;
//                        notifyDataSetChanged();
//                    } else if (list.get(position).level == 2) {
//                        getAreaByLevel(list.get(position).id + "", 2);
//                        tv_area.setText(currentProvince + "  " + list.get(position).areaname);
//                        currentCity = list.get(position).areaname;
//                        for (int i = 0; i < list.size(); i++) {
//                            list.get(i).flag = false;
//                        }
//                        list.get(position).flag = true;
//                        notifyDataSetChanged();
//                    } else if (list.get(position).level == 3) {
//                        getSchool(list.get(position).id + "");
//                        currentAreaId = list.get(position).id;
//                        tv_area.setText(currentProvince + "  " + currentCity + "  " + list.get(position).areaname);
//                        currentArea = list.get(position).areaname;
//                        for (int i = 0; i < list.size(); i++) {
//                            list.get(i).flag = false;
//                        }
//                        list.get(position).flag = true;
//                        notifyDataSetChanged();
//                        area_container.setVisibility(View.GONE);
//                        recyclerView_school.setVisibility(View.VISIBLE);
//                        isBack = false;
//                    }
//                }
//            });
//        }
//
//        @Override
//        public int getItemCount() {
//            return list.size();
//        }
//
//        class Holder extends RecyclerView.ViewHolder {
//            TextView tv_name;
//
//            public Holder(View itemView) {
//                super(itemView);
//                tv_name = itemView.findViewById(R.id.tv_name);
//            }
//        }
//    }
//
//
//    class MySchoolAdapter extends RecyclerView.Adapter<MySchoolAdapter.Holder> {
//
//        List<SchoolResponse.School> list;
//
//        public MySchoolAdapter(List<SchoolResponse.School> list) {
//            this.list = list;
//        }
//
//
//        @Override
//        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//            Holder holder = new Holder(getLayoutInflater().inflate(R.layout.item_area, parent, false));
//            return holder;
//        }
//
//        @Override
//        public void onBindViewHolder(final Holder holder, final int position) {
//            holder.tv_name.setText(list.get(position).name);
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    showSchoolDialog(currentAreaId, list.get(position).id);
//                    tv_area.setText(currentProvince + "  " + currentCity + "  " + currentArea + "  " + list.get(position).name);
//                    currentSchool = list.get(position).name;
//                }
//            });
//        }
//
//        @Override
//        public int getItemCount() {
//            return list.size();
//        }
//
//        class Holder extends RecyclerView.ViewHolder {
//            TextView tv_name;
//
//            public Holder(View itemView) {
//                super(itemView);
//                tv_name = itemView.findViewById(R.id.tv_name);
//            }
//        }
//    }
//
//
//    public void getAreaByLevel(String parentId, final int level) {
//        RestProxy.getInstance().getAreaByLevel(parentId, PreferencesHelper.getInstance().getString(this,"token"), new Observer<AreaResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(AreaResponse areaResponse) {
//                if (level == 0) {
//                    list_province.clear();
//                    list_province.addAll(areaResponse.data);
//                    myAdapter_province.notifyDataSetChanged();
//                } else if (level == 1) {
//                    list_city.clear();
//                    list_city.addAll(areaResponse.data);
//                    myAdapter_city.notifyDataSetChanged();
//                    list_area.clear();
//                    myAdapter_area.notifyDataSetChanged();
//                } else if (level == 2) {
//                    list_area.clear();
//                    list_area.addAll(areaResponse.data);
//                    myAdapter_area.notifyDataSetChanged();
//                }
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                e.printStackTrace();
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//
//    private void getSchool(String areaId) {
//        RestProxy.getInstance().getSchool(areaId, "",PreferencesHelper.getInstance().getString(this,"token"), new Observer<SchoolResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(SchoolResponse schoolResponse) {
//                list_school.clear();
//                list_school.addAll(schoolResponse.data);
//                myAdapter_school.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//
//
//    private void showSchoolDialog(int areaId, long parentId) {
////        if (mClassDialog == null) {
//        mClassDialog = mClassDialog.newInstance();
//        mClassDialog.areaId = areaId;
//        mClassDialog.parentId = parentId;
//        mClassDialog.show(getSupportFragmentManager(), "mClassDialog");
//        mClassDialog.setmListener(new ClassDialog.OnItemClickListener() {
//            @Override
//            public void onConfirm(String className) {
//                currentClass = className;
//                tv_area.setText(currentProvince + "  " + currentCity + "  " + currentArea + "  " + currentSchool + "  " + currentClass);
//            }
//        });
////        } else if (!mClassDialog.isAdded() && !mClassDialog.isShowing()) {
////            mClassDialog.show(getSupportFragmentManager(), "mClassDialog");
////        }
//    }
//
//
////    @BindView(R.id.checkbox_jkfc)
////    void checkbox_jkfc(){
////
////    }
//
//    public class MyLocationListener extends BDAbstractLocationListener {
//
//        @Override
//        public void onReceiveLocation(BDLocation location) {
//            //此处的BDLocation为定位结果信息类，通过它的各种get方法可获取定位相关的全部结果
//            //以下只列举部分获取地址相关的结果信息
//            //更多结果信息获取说明，请参照类参考中BDLocation类中的说明
//
//            String addr = location.getAddrStr();    //获取详细地址信息
//            String country = location.getCountry();    //获取国家
//            String province = location.getProvince();    //获取省份
//            String city = location.getCity();    //获取城市
//            String district = location.getDistrict();    //获取区县
//            currentLocation = district;
//            String street = location.getStreet();    //获取街道信息
//            if (TextUtils.isEmpty(province) || TextUtils.isEmpty(city) || TextUtils.isEmpty(district)) {
//
//            } else {
//                tv_location.setText(province + "  " + city + "  " + district);
//            }
////            System.out.println(addr + "   " + country + " " + province + " " + city + " " + district);
//        }
//    }
//
//    @OnClick(R.id.tv_location)
//    void tv_location() {
//        getSchoolId(currentLocation);
//        area_container.setVisibility(View.GONE);
//        recyclerView_school.setVisibility(View.VISIBLE);
//        isBack = false;
//    }
//
//    private void getSchoolId(String areaName) {
//        RestProxy.getInstance().getSchoolIdByName(areaName, PreferencesHelper.getInstance().getString(this,"token"),new Observer<IaBaseResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(IaBaseResponse iaBaseResponse) {
//                getSchool(iaBaseResponse.data);
//            }
//
//            @Override
//            public void onError(Throwable e) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        });
//    }
//
//}
//
//
